<?php
/*
 * Parent of Controller
 * - each controller will extend and inherit this parent class
 *
 * @author Andreas Psaros, presis.se
 */
class Controller {

    protected $entity;
    protected $model;
    protected $view;

    protected $action;
    protected $query;

    protected $post;
    protected $get;

    protected $render = true;

    /*
     * Initialize the class
     */
    function __construct($entity, $action, $query, $post, $get) {
        
        $this->entity = $entity;
        $this->action = $action;
        $this->query = $query;
        $this->post = $post;
        $this->get = $get;

        // set string for class name
        $modelClass = $entity.'Model';

        // init model
        $this->model = new $modelClass();

        // init view with relation to model
        $this->view = new View($entity,$action);
    }


    /*
     * Last call before the class is closed/destructed
     */
    function __destruct() {
        if($this->render)
            $this->view->render();
    }

    /*
     * Set a item/variable, make it avalible in view
     */
    function set($name,$value) {
        $this->view->set($name,$value);
    }


    /*
     * CRUD as generic defaults
     */
    function create(){
    }

    function read(){
    }

    function update(){
    }

    function delete(){
    }

}
?>